package com.geekchique.runningbuddy.provider;

import java.util.Calendar;

import com.geekchique.runningbuddy.util.DBHelperTools;

public class JogsDBSQL {
	public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "joggingLogs";
    
    public static final String DATABASE_TABLE1 = "joggingEntry";

    public static final String JOG_ID = "_id";
    public static final String JOG_NAME = "name";
    public static final String JOG_START_TIME = "startTime";
    public static final String JOG_STOP_TIME = "stopTime";
    
    
    public static String[] COLUMNS_IN_JOG_ENTRY = new String[] {
			JOG_ID,
		    JOG_NAME,
		    JOG_START_TIME,
		    JOG_STOP_TIME,
		};
    
    public static final String DATABASE_CREATE =
        "create table " 
    		+ JogsDBSQL.DATABASE_TABLE1 
        	+ " ("
    	    + JOG_ID + " integer primary key autoincrement, "
            + JOG_NAME + " text not null, "
            + JOG_START_TIME + " datetime,"
            + JOG_STOP_TIME + " datetime "
            + ");";
	
    public static final String WHERE_ENTRIES_WERE_TODAY =
    	"strftime( \"%Y-%m-%d\"," + JOG_STOP_TIME + ") = strftime( \"%Y-%m-%d\",'now');";

    public static final String WHERE_ENTRIES_WERE_THIS_MONTH =
    	"strftime( \"%Y-%m\"," + JOG_STOP_TIME + ") = strftime( \"%Y-%m\",'now');";

	public static String whereEntriesWereThisMonth(Calendar calendar) {
		String query = "strftime( \"%Y-%m\"," + JOG_STOP_TIME + ") = strftime( \"%Y-%m\",'"
			+ DBHelperTools.expectedFormat(calendar.getTimeInMillis())
			+ "');";
		
		return query; 
	}

	public static String getWhereCondition(Integer day, Integer month, Integer year) {
		String  dayString;
		String monthString;
		
		if(day < 10){
			dayString = "0" + day.toString();
		}else{
			dayString = day.toString();
		}
		
		if(month < 10){
			monthString = "0" + month.toString();
		}else{
			monthString = month.toString();
		}
		
		return "strftime( \"%Y-%m-%d\"," + JOG_STOP_TIME + ") = strftime( \"%Y-%m-%d\",\"" + year.toString() + "-"+ monthString + "-" + dayString +"T12:00:00.000\");";
	}
    
    
    //Entries must be entered into DB in YYYY-MM-DDTHH:MM:SS.SSS format
    
}
